package com.iris.live.services.services.impl;

import com.google.common.collect.Maps;
import com.iris.live.services.data.models.用户Model;
import com.iris.live.services.data.repositories.AccountRepository;
import com.iris.live.services.data.repositories.用户Repository;
import com.iris.live.services.services.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by Xin on 8/2/2016.
 */
@SuppressWarnings("SpringJavaAutowiringInspection")
@Service
@Transactional//(readOnly = true)
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountRepository accountRepository;

    @Autowired
    private 用户Repository 用户Repository;

    @Override
    public 用户Model getUser(String license, String username) {
        return this.用户Repository.findOne(username);
    }

    @Override
    public Map login(String license, String username, String password) {
        Map result = Maps.newHashMap();
        用户Model user = this.用户Repository.findActiveUser(license, username, password);
        if (user == null) {
            return result;
        }

        result.put("用户", user);
        List items = this.accountRepository.getAccessibleItems(user.get许可(), user.get用户名());
        result.put("权限", items);
        return result;
    }

    @Override
    public List getDuty(String permission) {

        return this.accountRepository.getDuty(permission);
    }

    @Override
    public List getAllSale(String permit) {
        return this.accountRepository.getAllSale(permit);
    }
}
